module keypad(clk, rst, rowA, rowB, rowC, rowD, colA, colB, colC, colD, colE, out_sel, count);
	input clk, rst;
	input colA, colB, colC, colD, colE;
	input[4:0] out_sel;
	output rowA, rowB, rowC, rowD;
	output[5:0] count;
	
	
	reg A, B, C, D;	
	reg[1:0] i;
	reg rowA, rowB, rowC, rowD;
	reg[4:0] count_1, count_2, count_3, count_4, count_5, count_6, count_7, count_8, count_9, count_0, count_up, count_down, count_left, count_right, count_unit, count_tare, count_enter, count_scrl_left, count_scrl_right, count_main;
	
		
	always@(posedge clk) begin
		i = i+1;
	end
	
	always@(negedge rst) begin
		{count_1, count_2, count_3, count_4, count_5, count_6, count_7, count_8, count_9, count_0, count_up, count_down, count_left, count_right, count_unit, count_tare, count_enter, count_scrl_left, count_scrl_right, count_main} = 0;
	end
	
	
	
	// row output scanning
/*	always begin
		case(i)
			2'b00: begin {rowA,rowB,rowC,rowD} = 4'b1000; end
			2'b01: begin {rowA,rowB,rowC,rowD} = 4'b0100; end
			2'b10: begin {rowA,rowB,rowC,rowD} = 4'b0010; end
			2'b11: begin {rowA,rowB,rowC,rowD} = 4'b0001; end
		endcase
	end
	*/
	// column input scanning and counting
	always begin
	  {A,B,C,D} = 0
		case({A,B,C,D});
			4'b1000: begin
				if(colA) count_1 = count_1 + 1;
				if(colB) count_2 = count_2 + 1;
				if(colC) count_3 = count_3 + 1;
				if(colD) count_up = count_up + 1;
				if(colE) count_main = count_main +1;
			end
			4'b0100: begin
				if(colA) count_4 = count_4 + 1;
				if(colB) count_5 = count_5 + 1;
				if(colC) count_6 = count_6 + 1;
				if(colD) count_down = count_down + 1;
				if(colE) count_unit = count_unit +1;
			end
			4'b0010: begin
				if(colA) count_7 = count_7 + 1;
				if(colB) count_8 = count_8 + 1;
				if(colC) count_9 = count_9 + 1;
				if(colD) count_left = count_left + 1;
				if(colE) count_tare = count_tare +1;
			end
			4'b0001: begin
				if(colA) count_scrl_left = count_scrl_left + 1;
				if(colB) count_0 = count_0 + 1;
				if(colC) count_scrl_right = count_scrl_right + 1;
				if(colD) count_right = count_right + 1;
				if(colE) count_enter = count_enter +1;
			end
		endcase
	end
	
	
	
endmodule